﻿using System;
using System.CodeDom;
using System.Linq;

namespace InterfaceWeaver.CustomTool
{
    public static class HookMethodHelper
    {
        /// <summary>
        /// Creates the hook method.
        /// </summary>
        /// <param name="methodName">Name of the method.</param>
        /// <param name="parameters">The parameters.</param>
        /// <returns></returns>
        public static CodeSnippetTypeMember CreateHookMethod(string methodName, params Tuple<string, string>[] parameters)
        {
            return new CodeSnippetTypeMember(
                string.Format("\t\tpartial void {0}({1});", 
                methodName,
                parameters != null
                 ? string.Join(", ", parameters.Select(param => string.Format("{0} {1}", param.Item1, param.Item2)))
                 : string.Empty));
        }

        /// <summary>
        /// Adds the hook method.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="methodName">Name of the method.</param>
        /// <param name="parameters">The parameters.</param>
        /// <returns></returns>
        public static CodeSnippetTypeMember AddHookMethod(this CodeTypeDeclaration type, string methodName, params Tuple<string, string>[] parameters)
        {
            var snippet = CreateHookMethod(methodName, parameters);
            type.Members.Add(snippet);
            return snippet;
        }
    }
}
